﻿@page "/grid"
<h3>GridUsing</h3>

<Grid TItem="WeatherForecast" DataProvider="WeatherDataProvider" Class="table table-hover">
    <GridColumn TItem="WeatherForecast" HeaderText="Date" PropertyName="Date">
        @context.Date
    </GridColumn><GridColumn TItem="WeatherForecast" HeaderText="TemperatureC" PropertyName="TemperatureC">
        @context.TemperatureC
    </GridColumn><GridColumn TItem="WeatherForecast" HeaderText="Summary" PropertyName="Summary">
        @context.Summary
    </GridColumn>
</Grid>
@code {
    private IEnumerable<WeatherForecast> forecasts = default!;
    private async Task<GridDataProviderResult<WeatherForecast>> WeatherDataProvider(GridDataProviderRequest<WeatherForecast> request)
    {
        var startDate = DateOnly.FromDateTime(DateTime.Now);
        var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
        forecasts = Enumerable.Range(1, 15).Select(index => new WeatherForecast
            {
                Date = startDate.AddDays(index),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = summaries[Random.Shared.Next(summaries.Length)]
            }).ToList();

        return await Task.FromResult(request.ApplyTo(forecasts));
    }
}
